package com.king.service.impl;

import com.king.annotation.Autowired;
import com.king.annotation.Service;
import com.king.annotation.Transactional;
import com.king.dao.AccountDao;
import com.king.pojo.Account;
import com.king.service.TransferService;

/**
 * @ClassName: TransferServiceImpl
 * @Description: TODO
 * @Author: wangchangyong
 * @Date: 2020/4/7 14:07
 * @Version: 1.0.0
 **/
@Service(value = "transferService")
@Transactional
public class TransferServiceImpl implements TransferService {

    @Autowired
    private AccountDao accountDao;

    // 构造函数传值/set方法传值
    // public void setAccountDao(AccountDao accountDao) {
    //     this.accountDao = accountDao;
    // }

    @Override
    public void transfer(String fromCardNo, String toCardNo, int money) throws Exception {

        Account from = accountDao.queryAccountByCardNo(fromCardNo);
        Account to = accountDao.queryAccountByCardNo(toCardNo);

        from.setMoney(from.getMoney() - money);
        to.setMoney(to.getMoney() + money);

        accountDao.updateAccountByCardNo(to);
        // int i = 1 / 0;
        accountDao.updateAccountByCardNo(from);

    }
}
